package com.ruoyi.wechat.api;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wechat.domain.Banner;
import com.ruoyi.wechat.domain.Camp;
import com.ruoyi.wechat.service.IBannerService;
import com.ruoyi.wechat.service.ICampService;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/wechat/camp")
public class WxCampController extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(WxCampController.class);
    @Autowired
    private ICampService campService;

    /**
     * 查询营地管理列表
     */

    @GetMapping("/list")
    public AjaxResult list()
    {
        //实例化对象 并且对象状态为显示
        Camp camp = new Camp();
        camp.setApprove("1");
        camp.setState("2");

        List<Camp> list = campService.selectCampList(camp);
        return success(list);
    }

    /**
     * 获取营地管理详细信息
     */
    @GetMapping(value = "/{campId}")
    public AjaxResult getInfo(@PathVariable("campId") String campId)
    {
        return success(campService.selectCampByCampId(campId));
    }

    /**
     * 新增营地管理
     */
    @PostMapping
    public AjaxResult add(@RequestBody Camp camp)
    {
        return toAjax(campService.insertCamp(camp));
    }

    /**
     * 修改营地管理
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Camp camp)
    {
        return toAjax(campService.updateCamp(camp));
    }

    /**
     * 删除营地管理
     */
    @DeleteMapping("/{campIds}")
    public AjaxResult remove(@PathVariable String[] campIds)
    {
        return toAjax(campService.deleteCampByCampIds(campIds));
    }
    /**
     * 搜索营地名称
     */
    @GetMapping("/search")
    public AjaxResult search(@RequestParam("campName") String campName) {
        logger.info("Received campName: {}", campName);
        List<Camp> camps = campService.searchCampsByName(campName);
        logger.info("Found camps: {}", camps);
        return success(camps);
    }
}
